package net.godbirds.market.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import net.godbirds.bean.Base;
import net.godbirds.bean.Product;
import net.godbirds.bean.Store;
import net.godbirds.market.service.MarketService;
import net.godbirds.market.service.StoreService;
import net.godbirds.market.service.WelcomeService;
/**
 * 超市控制器
 * @author Darker.Wang
 *
 */
@Controller
public class MarketController {
	@Autowired
	WelcomeService welcomeService;
	@Autowired
	MarketService marketService;
	@Autowired
	StoreService storeService;
	
	@GetMapping("/prdtemp")
	public String prdtemp(HttpServletRequest request,
			@RequestParam("group") String group,
			@RequestParam("start") int start,
			@RequestParam("step") int step) {
		//逻辑处理
		List<Product> navs = marketService.getProductByType(group, start, step);
		request.setAttribute("prds",navs);
		return "content/content-product::products";
	}
	
	@GetMapping("/storeUrl")
	public String store(HttpServletRequest request) {
		//逻辑处理
		List<Base> bases = welcomeService.getPrdBase();
		Store store = storeService.getStoreById(Long.parseLong("1"));
		List<Product> products = storeService.getProductByStoreId(store.getId());
		request.setAttribute("store",store);
		request.setAttribute("types",bases);
		request.setAttribute("products",products);
		request.setAttribute("user", "001");
		request.setAttribute("title", store.getName());
		return "store";
	}
}
